#include "stdafx.h"
#include "Event.h"

EventBus EventBus::instance;
using std::shared_ptr;

Event::Event()
{
}


Event::~Event()
{
}

EventBus::EventBus()
{
}

EventBus::~EventBus()
{
}

void EventBus::Register(Event * evt)
{
#define Reg(x) 	if (dynamic_cast<x*>(evt))instance.Register<x>(evt);
	Reg(IEventOnPalyerFail);
	Reg(IEventOnDamage);
	Reg(IEventOnRound);
	Reg(IEventOnRoundEnd);
	Reg(IEventOnDead);
	Reg(IEventOnUseCard);
	Reg(IEventHang);
}

EventResult EventBus::EventBusOnPalyerFail(TheRichMan & richman, TheRichManPlayerDate & playerdata, unsigned int playerid)
{
	return instance.SpreadEventBus<IEventOnPalyerFail>(&IEventOnPalyerFail::OnPalyerFail, ref(richman), ref(playerdata), playerid);
}

EventResult EventBus::EventBusOnDamage(Map & map, Entity & entity, Damage & dmg)
{
	return instance.SpreadEventBus<IEventOnDamage>(&IEventOnDamage::OnDamage, ref(map), ref(entity), ref(dmg));
}

EventResult EventBus::EventBusOnRound(Map & map, Entity & entity, size_t nRound)
{
	return instance.SpreadEventBus<IEventOnRound>(&IEventOnRound::OnRound, ref(map), ref(entity), nRound);
}

EventResult EventBus::EventBusOnRoundEnd(Map & map, Entity & entity, size_t nRound)
{
	return instance.SpreadEventBus<IEventOnRoundEnd>(&IEventOnRoundEnd::OnRoundEnd, ref(map), ref(entity), nRound);
}

EventResult EventBus::EventBusOnDead(Map & map, Entity & entity, Damage & dmg)
{
	return instance.SpreadEventBus<IEventOnDead>(&IEventOnDead::OnDead, ref(map), ref(entity), ref(dmg));
}

EventResult EventBus::EventBusOnUseCard(Map & map, Entity & user, Entity & aim, MapBlockPos pos, Card & card)
{
	return instance.SpreadEventBus<IEventOnUseCard>(&IEventOnUseCard::OnUseCard, ref(map), ref(user), ref(aim), pos, ref(card));
}

EventResult EventBus::EventBusOnHang(Map & map, Entity & entity)
{
	return instance.SpreadEventBus<IEventHang>(&IEventHang::OnHang, ref(map), ref(entity));
}

EventResult EventBus::EventBusOnRecover(Map & map, Entity & entity)
{
	return instance.SpreadEventBus<IEventHang>(&IEventHang::OnRecover, ref(map), ref(entity));
}
